package com.swjd.controller;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;

import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import com.swjd.po.user;
import com.swjd.service.UserService;

@Controller
public class UserController {
	@Autowired
	private UserService userService;

	// 登陆验证
	@RequestMapping("/login.action")
	public String login(@RequestParam("usercode") String user_code, @RequestParam("password") String user_password,
			Model model, HttpSession session) {
		user user = userService.findUserByUsercode(user_code);
		if (user != null) {
			if (user.getUser_password().equals(user_password)) {
				session.setAttribute("USER_SESSION", user);
				return "redirect:/customer/list.action";
			}
		}
		model.addAttribute("msg", "账户密码输入错误请重新输入！");
		return "login";
	}
	// 用户退出
	@RequestMapping("/logout.action")
	public String logout(HttpSession session) {
		session.removeAttribute("USER_SESSION");
		return "redirect:/index.jsp";
	}

}
